package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

func write(ch chan int) {
	for i := 0; i < 16; i++ {
		ch <- i
		time.Sleep(time.Second)
	}
	wg.Done()
}

func foo() {
	time.Sleep(time.Second * 25)
	wg.Done()
}

func main() {
	var ch1 chan int
	ch1 = make(chan int, 16)

	wg.Add(1)
	go write(ch1)
	wg.Add(1)
	go foo()

	for i := 0; i < 17; i++ {
		fmt.Println(<-ch1)
	}
	wg.Wait()
}
